package ys.ewp.facade;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import flex.messaging.FlexContext;

import ys.ewp.dto.AccountDto;
import ys.ewp.po.Account;
import ys.ewp.service.AccountService;

@Component
public class RightFacade {
	
	@Resource
	private AccountService accountService;
	
	/**
	 * @功能 如果账户信息正确则返回登陆账户对象，否则返回空对象
	 * @param accountCode
	 * @param password
	 * @return
	 */
	public AccountDto login(String accountCode, String password){
		Account account = this.accountService.login(accountCode, password);
		if(account != null){
			AccountDto accDto = AccountDto.getDtoByPo(account);
			accDto.setLoginTime(new Date());
			FlexContext.getFlexSession().setAttribute(accountCode, accDto);
			return accDto;
		}
		return null;
	}
	
	/**
	 * @功能 注销用户的登陆信息
	 * @param accountCode 账号
	 */
	public void logout(String accountCode){
		FlexContext.getFlexSession().removeAttribute(accountCode);
	}
	
}
